﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DungDungShit
{
	class MenuEntry
	{
		string text;
		//float selectionFade;
		Vector2 position;
		bool enable;

		public string Text
		{
			get { return text; }
			set { text = value; }
		}
		public Vector2 Position
		{
			get { return position; }
			set { position = value; }
		}
		public bool Enable
		{
			get { return enable; }
			set { enable = value; }
		}

		public event EventHandler<EventArgs> Selected;
		protected internal virtual void OnSelectEntry()
		{
			if (Selected != null)
				Selected(this, new EventArgs());
		}

		public MenuEntry(String text)
		{
			this.text = text;
			this.enable = true;
		}

		public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime)
		{
			// there is no such thing as a selected item on Windows Phone, so we always
			// force isSelected to be false
#if WINDOWS_PHONE
			isSelected = false;
#endif
			// When the menu selection changes, entries gradually fade between
			// their selected and deselected appearance, rather than instantly
			// popping to the new state.
			/*
			float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

			if (isSelected)
				selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
			else
				selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
			*/
		}

		public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
		{
#if WINDOWS_PHONE
			isSelected = false;
#endif

			// 선택 여부에 따라 색이 다름
			Color color = enable ? isSelected ? Color.SkyBlue : Color.White : Color.Gray;

			// Modify the alpha to fade text out during transitions.
			color *= screen.TransitionAlpha;

			// Draw text, centered on the middle of each line.
			ScreenManager screenManager = screen.ScreenManager;
			SpriteBatch spriteBatch = screenManager.SpriteBatch;
			SpriteFont font = screenManager.Font;

			Vector2 origin = new Vector2(GetWidth(screen) / 2, font.LineSpacing / 2);

			spriteBatch.DrawString(font, text, position, color, 0,
				origin, isSelected ? 1.2f : 1.0f, SpriteEffects.None, 0);
		}


		public virtual int GetHeight(MenuScreen screen)
		{
			return screen.ScreenManager.Font.LineSpacing;
		}

		public virtual int GetWidth(MenuScreen screen)
		{
			return (int)screen.ScreenManager.Font.MeasureString(Text).X;
		}

	}
}
